﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Component
{
    public class Config
    {
        public static TimeSpan CatchTimeSpan
        {
            get
            {
                try
                {
                    double day = Convert.ToDouble(ConfigurationManager.AppSettings["CatchTime"].ToString());
                    if (day == 0)
                        day = 100;
                    return TimeSpan.FromDays(day);

                }
                catch
                {
                    return TimeSpan.FromDays(100);
                }
            }
        }
        public static string GetValue(string tagName)
        {
            return Convert.ToString(ConfigurationManager.AppSettings[tagName]);
        }

        public static string GetPathXMLOfFileName(string fileNameXML)
        {
            return GetValue("RootDirectoryFileXML") + "/" + fileNameXML;
        }

        public Config()
        {

        }
        //Phan file
        public static string AcceptFileType()
        {
            return ImageFile() + "," + FlashFile() + "," + MediaFile() + "," + ArchiveFile();
        }

        //<!--Phan file upload-->
        //    <add key="IMGSuccess" value="Admin/Images/Icons/ok.gif"/>
        //    <add key="IMGError" value="Admin/Images/Icons/error.gif"/>
        //    <add key="FCKEditor:UserFilesPath" value="~/FileUpload/FCKUpload/"/>
        //    <add key="FCKEditor:BasePath" value="~/fckeditor"/>
        //    <add key="ImageFile" value="gif;png;jpg;bmp"/>
        //    <add key="FlashFile" value="swf"/>
        //    <add key="MediaFile" value="wma;mp4;mp3;flv;wmv;avi"/>
        //    <add key="ArchiveFile" value="zip;rar;tar"/>
        public static string ImageFile()
        {
            return ConvertType.ToString(ConfigurationManager.AppSettings["ImageFile"]).ToLower();
        }
        public static string FlashFile()
        {
            return ConvertType.ToString(ConfigurationManager.AppSettings["FlashFile"]).ToLower();
        }
        public static string MediaFile()
        {
            return ConvertType.ToString(ConfigurationManager.AppSettings["MediaFile"]).ToLower();
        }
        public static string ArchiveFile()
        {
            return ConvertType.ToString(ConfigurationManager.AppSettings["ArchiveFile"]).ToLower();
        }
        /// <summary>
        /// Kiem tra file co duoc chap nhan hay ko ?
        /// </summary>
        /// <param name="fileType">Phan mo rong cua file</param>
        /// <returns></returns>
        public static bool CheckAcceptFile(string fileType)
        {
            string type = AcceptFileType();
            if (fileType == "")
                return false;
            if (type.ToLower().Contains(fileType.ToLower()) == true)
                return true;
            return false;
        }
    }
}



